<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/define/dbmeta"/>

<div class="pageContent">

	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="edit" onclick="saveDbMeta();" title="保存"><span>保存</span></a></li>
			<li class="line">line</li>
			<li><a class="delete" onclick="deleteDbMeta();"><span>删除</span></a></li>
		</ul>
	</div>

	<form name="action_set_form" method="post" action="${path}/save.html" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
		<div class="pageFormContent" layoutH="270" >
			<fieldset>
				<dl >
					<dt>数据库名称：</dt>
					<dd>
						<select name="name" id="name" class="combox" >
							<option value="mysql"  <c:if test="${name == 'mysql'}">selected="selected"</c:if> >MYSQL</option>
							<option value="oracle"  <c:if test="${name == 'oracle'}">selected="selected"</c:if> >ORACLE</option>
						</select>
					</dd>
				</dl>
				<dl >
					<dt>启用：</dt>
					<dd><input name="used" id="used" type="checkbox" <c:if test="${bean.used}">checked</c:if> /></dd>
				</dl>
			</fieldset>
		</div>

		<div class="pageFormContent" layoutH="130">
		<div class="tabs">
			<div class="tabsHeader">
				<div class="tabsHeaderContent">
					<ul>
						<li class="selected"><a href="javascript:void(0)"><span>字段类型列表</span></a></li>
					</ul>
				</div>
			</div>
			<div class="tabsContent" style="height:170px;">
				<div>
					<table class="list nowrap itemDetail" addButton="添加类型" width="100%">
						<thead>
							<tr>
								<th type="text" name="items.name[#index#]" size="20" fieldClass="required">类型名称</th>
								<th type="text" name="items.dbType[#index#]" size="20" fieldClass="required">数据库类型</th>
								<th type="text" name="items.javaType[#index#]" size="20" fieldClass="required">Java类型</th>
								<th type="del" width="30">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:if test="${! empty bean.dataMetas }">
							<c:forEach var="data" items="${bean.dataMetas}" varStatus="status">
							<tr>
								<td><input type="text" class="textInput" size="20" value="${data.name}" name="items.name[${status.index}]" /></td>
								<td><input type="text" class="textInput" size="20" value="${data.dbType}" name="items.dbType[${status.index}]" /></td>
								<td><input type="text" class="textInput" size="20" value="${data.javaType}" name="items.javaType[${status.index}]" /></td>
								<td><a class="btnDel " href="javascript:void(0)">删除</a></td>
							</tr>
							</c:forEach>
							</c:if>
						</tbody>
					</table>
				</div>
								
			</div>
			
			<div class="tabsFooter">
				<div class="tabsFooterContent"></div>
			</div>
		</div>

		</div>
		
	</form>
</div>
<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alertMsg.correct(json.message);
		if(json.callbackType){
			var str = $("#name").val();
			var url = "${path}/list.html";
			navTab.reload(url,null,"base_define_dbmeta_list");
			// navTab.reload(url);
			//navTab.reloadFlag("base_define_action_list"); // 下次切换到列表页签时需要刷新一下
			setTimeout(function(){$.pdialog.closeCurrent();}, 100); // 关闭此编辑页签
		}
	}
}

function saveDbMeta(){
	$(action_set_form).submit();
}

function deleteDbMeta(){
	var rel = '';
	$('.base_define_dbmeta_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		alertMsg.confirm("确定要删除吗?", {
			okCall: function(){
				var url = "${path}/delete.html?name=" + rel;
				$.ajax({
					type: "post", url: url,
					success: function(json){
						alertMsg.correct(json.msg);
						var url = "${path}/list.html";
						navTab.reload(url);
						setTimeout(function(){$.pdialog.closeCurrent();}, 100); // 关闭此编辑页签
					},
					error: function(){
						alertMsg.error('系统错误，请联系管理员！');
					}
				});
			}
		});
	}
}

</script>
